
/*
    Microformats Phone Number Canonicalisation 0.1
    Author: Glenn Jones
    
	The MIT License
	
	Copyright (c) 2008 Glenn Jones
	
	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:
	
	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.
	
	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
	
	Although phone numbers are not consider to be just a string value in the 
	Microformats specifications some parsers do treat them as a data type and 
	perform different levels of validation. To allow the test-runner to test 
	parsers equally the following method canonicalise and compare phone 
	numbers.  
	
*/




function PhoneNumber() {
    this.raw = "";
    this.canonicalisation = "";	
	if(arguments[0])
		this.Parse( arguments[0] );
}

PhoneNumber.prototype.Reset = function(){
    this.raw = "";
    this.canonicalisation = "";
}

PhoneNumber.prototype.Parse = function( text ) {
	this.Reset();
    this.raw = text;
    text = text.replace(" ", "");
    var parts = text.match(/[0-9\+]/g);
	if( Object.isArray(parts))
	{
    	for (var i = 0; i < parts.length; i++) {
    		this.canonicalisation += parts[i];
    	}
	}
}

PhoneNumber.prototype.toString = function() {
	return this.canonicalisation;
}

function ComparePhoneNumbers( phoneNumber1, phoneNumber2 ) {
	var test1 = new PhoneNumber( phoneNumber1 ).toString();
	var test2 = new PhoneNumber( phoneNumber2 ).toString();
	if( ( test1 == '') && (test2 == '') ){
		return false;
	}else{
		if( test1 == test2 )
			return true;
		else
			return false;
     }
}







// Tests
 //alert( new ISODate('2008-01-21').toString() + ' - 2008-01-21' ) ;

//alert(ISODateNormalisation( '2008-01-21' ) + ' - 2008-01-21' ) ;
//alert(ISODateNormalisation( '20080121' ) + ' - 20080121' ) ;
//alert(ISODateNormalisation( '2007-05-01T11:30') + ' - 2007-05-01T11:30' );
//alert(ISODateNormalisation( '2007-05-01 11:30' ) + ' - 2007-05-01 11:30');
//alert(ISODateNormalisation( '20070501 11:30' ) + ' - 20070501 11:30');
//alert(ISODateNormalisation( '20070501T1130' ) + ' - 20070501T1130') ;
//alert(ISODateNormalisation( '2007-05-01T11:30:15' ) + ' - 2007-05-01T11:30:15') ;
//alert(ISODateNormalisation( '20070501T113015' ) + ' - 20070501T113015') ;
//alert(ISODateNormalisation( '2007-05-01T11:30Z-08:00' ) + ' - 2007-05-01T11:30Z-08:00') ;
//alert(ISODateNormalisation( '2007-05-01T11:30-08:00' ) + ' - 2007-05-01T11:30-08:00') ;
//alert(ISODateNormalisation( '2007-05-01T11:30+08:00' ) + ' - 2007-05-01T11:30+08:00') ;
//alert(ISODateNormalisation( '2007-05-01T11:30Z08:00' ) + ' - 2007-05-01T11:30Z08:00') ;
//alert(ISODateNormalisation( '20070501T1130Z-0800' ) + ' - 20070501T1130Z-0800') ;
//alert(ISODateNormalisation( '2007-05-01T11:30Z' ) + ' - 2007-05-01T11:30Z') ;
//alert(ISODateNormalisation( '2007-05' ) + ' - 2007-05') ;
//alert(ISODateNormalisation( '07-05-01' ) + ' - 07-05-01') ;
//alert(ISODateNormalisation( '070501' ) + ' - 070501') ;




  	


